package com.tian.producer;

import com.alibaba.fastjson.JSON;
import com.tian.constant.RabbitMQConstant;
import com.tian.enums.MessageRetryType;
import com.tian.message.UserGetCouponAdditionalMessage;
import com.tian.message.UserGetCouponMessage;
import com.tian.util.BaseProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * {@code @description:} 用户领取优惠券消息生产者
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-08-17 20:20
 * {@code @version:} 1.0
 */
@Slf4j
@Component
public class UserGetCouponProducer {
    @Resource
    private BaseProducer baseProducer;

    public void sendUserGetCoupon(UserGetCouponMessage userGetCouponMessage) {
        String content = JSON.toJSONString(userGetCouponMessage);
        baseProducer.sendWithRetry(content, MessageRetryType.USER_GET_COUPON.getCode(),userGetCouponMessage.getReqId(),
                RabbitMQConstant.USER_GET_COUPON_EXCHANGE, RabbitMQConstant.USER_GET_COUPON_ROUTING_KEY);
    }
    public void sendUserGetCouponAdditional(UserGetCouponAdditionalMessage userGetCouponAdditionalMessage) {
        String content = JSON.toJSONString(userGetCouponAdditionalMessage);
        baseProducer.sendWithRetry(content, MessageRetryType.USER_GET_COUPON_ADDITIONAL.getCode(),userGetCouponAdditionalMessage.getReqId(),
                RabbitMQConstant.USER_GET_COUPON_ADDITIONAL_EXCHANGE, RabbitMQConstant.USER_GET_COUPON_ADDITIONAL_ROUTING_KEY);
    }
}
